package com.tieto.user.service;

import java.util.List;
import java.util.Vector;

import javax.annotation.PostConstruct;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import com.tieto.user.dto.User;

public class UserManagementStub implements UserManagement {
	protected List<User> users = new Vector<User>();
	Logger logger = LogManager.getLogger(UserManagementStub.class);

	@PostConstruct
	public void initialize() {
		save(new User("admin", "admin", "admin"));
	}

	@Override
	public long count() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void delete(Iterable<? extends User> entities) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(String username) {
		User existingUser = findOne(username);
		if (existingUser != null) {
			users.remove(existingUser);
		}
	}

	@Override
	public void delete(User entity) {
		// TODO Auto-generated method stub

	}

	@Override
	public void deleteAll() {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean exists(String id) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Iterable<User> findAll() {
		logger.debug("UserManagementStub.read()");
		return users;
	}

	@Override
	public User findOne(String username) {
		for (User user : users) {
			if (user.getUsername().equals(username)) {
				return user;
			}
		}
		return null;
	}

	@Override
	public Iterable<User> save(Iterable<? extends User> arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public User save(User user) {
		users.add(user);
		return null;
	}
}
